// ---------------------------------------------------------------------
//
//	Copyright 2003 e Professional Co.,Ltd.  All Rights Reserved.
//
//	File : lov.js
//
//	Description : The callLov javascript  provides function to access
//				LOV (List of value) file. The LOV will open in modal dialog
//				window and return value to parent window. 
//
//-------------------------------------------------------------------- 

//------------------------------------------------------------------------
//
//	Function : showLov
//
//	Synopsis : This function is use for open LOV window (modal window).
//				Opened lov window will return value(s) to parent window. 
//
//	Arguments : This function receive 4 arguments (2 required) 
//			*	urlLov - String that specifies the URL of the LOV to display. 
//			*	returnObj - Object that will receive return value from LOV. 
//				size - String that specifies the size of the window. 
//				nextItem - The item that cursor will focus after close LOV dialog
//
//	Returns : none.
//
//	Notes : none
//
//------------------------------------------------------------------------
function showLov(urlLov, returnObj, size, nextItem, isMultiple) {
//alert('urlLov='+urlLov+', returnObj='+returnObj+', size='+size+', nextItem='+nextItem+', isMultiple='+isMultiple) ;
	var clearObjs = returnObj.split("|") ;
//	for(i = 0 ; i < clearObjs.length ; i++)
//		eval(clearObjs[i]).value = '' ;
//	alert('from showLov') ;
// Set default value for run function
	defaultSize = "s"; // Default size of window
	features = "dialogWidth:400px; dialogHeight:400px;";

// Check value of arguments and assign appropriate value
	size = (size == undefined || size == "") ? defaultSize : size ;
	if (size.toLowerCase() == "s") {
		features = "dialogWidth:400px; dialogHeight:500px;";
	} else if (size.toLowerCase() == "m") {
		features = "dialogWidth:600px; dialogHeight:500px;";
	} else if (size.toLowerCase() == "l") {
		features = "dialogWidth:800px; dialogHeight:500px;";
	}
	features += 'scroll: no;' ;
// Define appropriate url and querystring of LOV
//alert(urlLov) ;
	 var url = urlLov.split("?");
//	 urlLov = url[0];
	/*
		Add support encode charactor.
	*/
	var p = document.location.href ;
	p = p.replace('http://', '') ;
	p = p.replace(document.location.search, '') ;
	var pSplit = p.split("/") ;
	var frameLoc = '', lovLoc = '' ;
//alert();
	for(i = 2 ; i < pSplit.length-1 ; i++) {
		frameLoc += '../' ;
		lovLoc += pSplit[i] + '/' ;
	}

	 urlLov = frameLoc + 'LOVFRAME.jsp' ;
	 if (url.length>1) {
		var pair = url[1].split("&") ;
		for(i = 0 ; i < pair.length ; i++) {
			var temp = pair[i].split("=") ;
//			returnObj += "&"+temp[0]+"="+escape(temp[1]);
			returnObj += "&"+temp[0]+"="+temp[1];
		}
	 }
	 urlLov += "?lovName="+(lovLoc + url[0])+"&returnObj="+returnObj;
	// alert('urlLov : ' + urlLov);
//	 if(isMultiple != undefined && isMultiple != "")
	 	urlLov += "&isMultiple="+isMultiple;
	 //alert('lovLoc : ' + lovLoc);
	 //alert('url[0] : ' + url[0]);
// Show LOV in modal window
	 window.showModalDialog(urlLov, window, features); 
	 if(nextItem != undefined && nextItem != "") {
	 	hasValue = false ;
	 	for(i = 0 ; i < clearObjs.length ; i++)
	 		if(eval(clearObjs[i]).value != '') {
	 			hasValue = true ;
	 			break ;
	 		}

	 	if(hasValue) {
		 	eval(nextItem).focus() ;
		 } else {
		 	eval(nextItem).focus() ;
		 	eval(clearObjs[0]).focus() ;
		 }
	 } else {
	 //	alert("Not Found Item Name or ID '"+nextItem+"'");
	 }
}


function showMultiLov(urlLov, returnObj, size) {
// Set default value for run function
	defaultSize = "s"; // Default size of window
	features = "dialogWidth:400px; dialogHeight:400px;";

// Check value of arguments and assign appropriate value
	size = (size == undefined || size == "") ? defaultSize : size ;
	if (size.toLowerCase() == "s") {
		features = "dialogWidth:400px; dialogHeight:500px;";
	} else if (size.toLowerCase() == "m") {
		features = "dialogWidth:600px; dialogHeight:500px;";
	} else if (size.toLowerCase() == "l") {
		features = "dialogWidth:800px; dialogHeight:500px;";
	}

// Define appropriate url and querystring of LOV
	 var url = urlLov.split("?");
	 urlLov = url[0];
	 if (url.length>1)
		 returnObj += "&"+url[1];
	 urlLov += "?returnObj="+returnObj;

// Show LOV in modal window
	 window.showModalDialog(urlLov, window, features); 
}

function returnMyValue(num) 
{
	var objstr = "";
	for (i=0;i<objReturn.length;i++)
	{
//		str = "dialogArguments."+ objReturn[i].toString();
		str = "opener."+ objReturn[i].toString();
		objstr = str;
		obj = eval(objstr);
		obj.value= eval("myArray"+i)[num]; 
	}
//	if (error == false)
		window.close();
}

function clearSpecialChar(str) {
	while(str.indexOf('#') >= 0) {
		str = str.replace('#', '%23') ;
	}
	return str ;
}